package com.lhd.egmvc1.controller;

import com.lhd.egmvc1.mapper.EmpMapper;
import com.lhd.egmvc1.pojo.entity.Emp;
import com.lhd.egmvc1.pojo.vo.EmpVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lhd
 * @date 2024/4/23
 * @apiNote
 */
@RestController
@RequestMapping(value ="/emp/")
public class EmpController {
    @Autowired
    private EmpMapper empMapper;

    /**
     * 添加员工
     * @param emp
     * @return
     */
    @PostMapping(value = "insert")
     public String insert(Emp emp){
         empMapper.insert(emp);
         return "添加成功";
     }


     @GetMapping(value = "select")
      public List<EmpVO> selectAllEmpsOfNameAndJob(){

        return empMapper.selectAllEmpsOfNameAndJob();
      }
      @PostMapping(value = "update")
       public String update(Emp emp){
          empMapper.update(emp);
          return "修改成功";
      }

      @GetMapping(value = "delete")
      public String delete(int id){
          empMapper.deleteById(id);
          return "删除成功";
      }

}
